package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark59Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark59 extends BaseMark {

    LayoutWatermark59Binding binding;

    public Mark59(@NonNull Context context) {
        super(context);
    }

    public Mark59(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark59(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark59Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            int n = binding.linear.getChildCount();
            for (int i = 2; i < n; i++) {
                binding.linear.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark59Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "text59", binding.binding1);
        setText(binding.binding2, "phone59", binding.phone);
        setText(binding.binding4, "content59", binding.binding3);
        setText(binding.binding6, "time59", binding.binding5);
        setTime(binding.binding6, new SimpleDateFormat("yyyy.MM.dd HH:mm"));

        setText(binding.binding8, "weather59", binding.binding7);
        setText(binding.binding10, "didian59", binding.binding9);
        setText(binding.binding12, "height59", binding.binding11);
        setText(binding.binding14, "angle59", binding.binding13);
        setText(binding.binding16, "jingwei59", binding.binding15);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("text59", "自定义"));
        list.add(new EditItem("phone59", "联系方式"));
        list.add(new EditItem("content59", "业务内容"));

        list.add(new EditItem("time59", "时间", true));
        list.add(new EditItem("weather59", "天气"));
        list.add(new EditItem("didian59", "地点"));
        list.add(new EditItem("height59", "海拔"));
        list.add(new EditItem("angle59", "方位角"));
        list.add(new EditItem("jingwei59", "经纬度"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding6, new SimpleDateFormat("yyyy.MM.dd HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
